import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Icon } from 'antd';
import { bindActionCreators } from 'redux';
import SearchList from './SearchList/SearchList';
import { CommonTable } from 'components';
import { listNotifyResultAction } from './index';
import styles from './ListNotifyResult.less';
import moment from 'moment';
import { axios } from 'utils';
const convertarams = (obj = {}) => {
    const { time = [], type = '' } = obj;
    const isArr = Array.isArray(time) && time.length > 0;
    return {
        startTime: isArr ? time[0].format('YYYY-MM-DD') : '',
        endTime: isArr ? time[1].format('YYYY-MM-DD') : '',
        type
    };
}

class listNotifyResult extends Component{

    constructor(props) {
        super(props);
        this.state = {};
        this.pageSize = 10;
        this.searchParams = convertarams({});
        this.columns = [
            {
                title: '手机号码',
                dataIndex: 'phone',
                key: 'phone'
            },
            {
                title: '姓名',
                dataIndex: 'name',
                key: 'name'
            },
            {
                title: '身份证号',
                dataIndex: 'idcard',
                key: 'idcard'
            },
            {
                title: '渠道ID',
                dataIndex: 'channelId',
                key: 'channelId'
            },
            {
                title: '提醒次数',
                dataIndex: 'count',
                key: 'count'
            }

        ];
    }
    componentDidMount() {
        const { getTableData } = this.props;
        getTableData({ pageSize: this.pageSize, pageNum: 1, ...this.searchParams });

    }

    componentWillUnmount() {
        const { setTableData } = this.props;
        setTableData({
            data: [],
            pagination: {}
        })
    }

    handleSearch = (obj) => {
        const { getTableData } = this.props;
        const params = convertarams(obj);
        getTableData({ pageSize: this.pageSize, pageNum: 1, ...params });
    }
    handlePageChange = (info) => {
        const { current, pageSize } = info;
        const { getTableData } = this.props;
        getTableData({ pageNum: current, pageSize, ...this.searchParams });
    }

    render() {
        const { tableData: { data, pagination }, loading } = this.props;
        return (
            <div>
                <SearchList submit={this.handleSearch}/>
                <CommonTable handlePageChange={this.handlePageChange} columns={this.columns} dataSource={data} pagination={pagination} loading={loading}/>
</div>
        );
    }
}
const mapStateToProps = (state) => {
    const { liushiState: { listNotifyResultState } } = state;
    return {
        tableData: listNotifyResultState['data'],
        loading: listNotifyResultState['loading']
    }
};
const mapDispatchToProps = (dispatch) => {
    return bindActionCreators({
        getTableData: listNotifyResultAction.lnrGetTableData,
        setTableData: listNotifyResultAction.lnrSetTableData
    },dispatch)
}
export default connect(mapStateToProps, mapDispatchToProps)(listNotifyResult);